const tipsStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 10,
	fill: ['#778899'],
	stroke: '#181818',
	strokeThickness: 2
});

const smallStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 12,
	fontStyle: 'italic',
	fill: ['#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const bigStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 24,
	fill: ['#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const propertyStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 20,
	fill: ['#F8E800', '#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const nameStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 13,
	fill: ['#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const panelHeadStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 15,
	fontWeight: 'bold',
	fill: ['#384030'],
	stroke: '#181818',
	strokeThickness: 0
});

const textStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 16,
	fill: ['#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const selectedStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 16,
	fontWeight: 'bold',
	fill: ['#F8F8A0'],
	stroke: '#D85000',
	strokeThickness: 3
});

const unenableStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 16,
	fontWeight: 'bold',
	fill: ['#858584'],
	stroke: '#4A4A49',
	strokeThickness: 3
});

const spStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 16,
	fontStyle: 'italic',
	fontWeight: 'bold',
	fill: ['#78C8E8', '#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const hpStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 16,
	fontStyle: 'italic',
	fontWeight: 'bold',
	fill: ['#F8A898', '#FCFCFC'],
	stroke: '#181818',
	strokeThickness: 3
});

const talkStyle = new PIXI.TextStyle({
	fontFamily: 'Arial',
	fontSize: 14,
	fontWeight: 'bold',
	fill: ['#201000'],
	wordWrap: true,
	breakWords:true,
	wordWrapWidth: 240,
	lineJoin: 'round',
	dropShadow: true,
	dropShadowColor: '#D0C890',
	dropShadowBlur: 1,
	dropShadowAngle: Math.PI / 6,
	dropShadowDistance: 3,
});

const numberStyle = new PIXI.TextStyle({
	fontFamily: 'Arial',
	fontSize: 14,
	fill: ['#201000'],
	dropShadow: true,
	dropShadowColor: '#D0C890',
	dropShadowBlur: 1,
	dropShadowAngle: Math.PI / 6,
	dropShadowDistance: 2,
});

const numberSelectedStyle = new PIXI.TextStyle({
	fontFamily: 'Microsoft YaHei',
	fontSize: 13,
	fill: ['#F8F8A0'],
	stroke: '#D85000',
	strokeThickness: 2
});

const xStyle = new PIXI.TextStyle({
	fontFamily: 'Arial',
	fontSize: 16,
	fill: ['#585038'],
	dropShadow: true,
	dropShadowColor: '#C0C0A8',
	dropShadowBlur: 1,
	dropShadowAngle: Math.PI / 6,
	dropShadowDistance: 2,
});

class UIManager extends PIXI.Container {
	constructor() {
		super();
	}

	/**
	 * 当按下按钮时
	 */
	keyDown(key) {
		if(this._lastKey != key || (new Date().getTime() - this._lastKeyTime > 200)) {
			if(this.children.length > 0 && this.children[this.children.length - 1].keyDown)
				this.children[this.children.length - 1].keyDown(key);

			this._lastKey = key;
			this._lastKeyTime = new Date().getTime();
		}
	}

	/**
	 * 当更新时发生
	 */
	update() {
		for(var i = 0 ; i < this.children.length; i++)
			if(this.children[i].update)
				this.children[i].update();
	}
	
	/**
	 * 显示队伍界面
	 */
	party() {
		new Party(this);
	}

	/**
	 * 显示对话框
	 * @param {*} talker 
	 * @param {*} context 
	 * @param {*} option 
	 */
	talk (talker, context, option) {
		this.lastTalker = talker;
		this.lastContext = context;
		return new Promise(resolve => new Talk(this, talker, context, option, resolve));
	}
	
	/**
	 * 显示菜单,必须在talk后调用
	 * @param {*} items 
	 * @param {*} option 
	 */
	menu (items, option) {
		return new Promise(resolve => new TalkMenu(this, items, this.lastTalker, this.lastContext, option, resolve));
	}

	/**
	 * 开启指定物品商店
	 * @param {*} items 
	 * @param {*} option 
	 */
	buy (items, callback) {
		return new Promise(resolve => new Shop(this, {isSell:false,items,callback}, resolve));
	}

	/**
	 * 开启贩售商店
	 * @param {*} option 
	 */
	sell (callback) {
		return new Promise(resolve => new Shop(this, {isSell:true,callback}, resolve));
	}
}

L2D.UIManager = new UIManager();
L2D.UserInterface = new PIXI.Container();